<!DOCTYPE html>
<html lang="en">
    <head>
    <meta echarset="UTF-8">
    <mate http-equiv="X-UA-Compatible" content="IE=edge">
    <mate name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Document</title>
    <script>
        function abc(){
            var oldstr = document.getElementById('old');
            var newstr = document.getElementById('new');
            var reg=/^\s*|\s*$/g;
            newstr.value=oldstr.value.replace(reg,'')

        }

    </script>
    </head>
    <body>
        过滤前：<input type="text" id="old">
        <button onclick="abc()">过滤空格<tton><br>
        过滤后：<input type="text" id="new">
    </body>



</html>